package com.jxaummd.mushroom.main.common.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.jxaummd.mushroom.R;
import com.jxaummd.mushroom.R2;
import com.jxaummd.mushroom.core.app.activity.ActivityManager;
import com.jxaummd.mushroom.core.base.fragment.PresenterFragment;
import com.jxaummd.mushroom.core.util.ui.status.StatusBarCompat;
import com.jxaummd.mushroom.main.EcBottomFragment;
import com.jxaummd.mushroom.main.common.contract.LoginContract;
import com.jxaummd.mushroom.main.common.presenter.LoginPresenter;

import butterknife.BindView;
import butterknife.OnClick;

public class LoginFragment extends PresenterFragment<LoginContract.Presenter> implements LoginContract.View {

    @BindView(R2.id.ec_tiet_common_login_username)
    TextInputEditText mEditUserName = null;

    @BindView(R2.id.ec_tiet_common_login_password)
    TextInputEditText mEditPassWord = null;

    @BindView(R2.id.ec_tv_common_login_signup)
    TextView mTextSignup = null;

    @BindView(R2.id.ec_tv_common_login_forget_password)
    TextView mTextForgetPassword = null;


    @OnClick(R2.id.ec_btn_common_login_submit)
    public void submit() {
        String phoneNumber = mEditUserName.getText().toString();
        String password = mEditPassWord.getText().toString();
        String hint = "";
        if (TextUtils.isEmpty(password)) {
            hint = "密码要填的啦！不填是不可能让你登录的，这辈子都不会登录的~";
        }
        if (TextUtils.isEmpty(phoneNumber)) {
            hint = "用户名要填的啦！不填是不可能让你登录的，这辈子都不会登录的~";
        }
        if (hint.length() < 2) {
            mPresenter.login(phoneNumber, password);
        } else {
            ToastUtils.showShort(hint);
        }
    }


    @Override
    protected LoginContract.Presenter initPresenter() {
        return new LoginPresenter(this);
    }

    @Override
    public Object setLayout() {
        return R.layout.common_login;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
        mPresenter.start();
    }

    @Override
    public void setNoStatusBar() {
        //设置非全屏
        StatusBarCompat.setFullScreen(getProxyActivity(), StatusBarCompat.STATUEBAR_NORMAL);
        //设置状态栏和字体的颜色
        StatusBarCompat.setStatuebarTextColor(getProxyActivity(), getResources().getColor(R.color.white));
    }

    @Override
    public void loginSuccess() {
        startWithPop(EcBottomFragment.newInstance());
    }
}
